package com.goods.controller.business;

import com.goods.business.service.SupplierService;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@SuppressWarnings("all")
@RestController
@RequestMapping("/business/supplier")
public class SupplierController {
    @Autowired
    private SupplierService supplierService;

    //物资来源(地址)列表
    @GetMapping("/findSupplierList")//VO会是空吗?
    public ResponseBean<PageVO<SupplierVO>> findSupplierList(int pageNum, int pageSize, SupplierVO supplierVO) {
        System.out.println(supplierVO);//至少不全是null
        PageVO<SupplierVO> supplierVOList = supplierService.findSupplierList(pageNum, pageSize, supplierVO);
        return ResponseBean.success(supplierVOList);
    }

    //添加物资来源(地址)
    @PostMapping("/add")
    public ResponseBean add(@RequestBody SupplierVO supplierVO) {
        supplierService.add(supplierVO);
        return ResponseBean.success();
    }

    //修改时回显物资来源(地址)信息
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id) {
        Supplier supplier = supplierService.selectSupplierById(id);
        return ResponseBean.success(supplier);
    }

    //修改物资来源信息
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id, @RequestBody Map editRuleForm) {
        supplierService.update(id, editRuleForm);
        return ResponseBean.success();
    }

    //删除物资来源信息
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id) {
        supplierService.delete(id);
        return ResponseBean.success();
    }

    //获取所有物资来源地址
    @GetMapping("/findAll")
    public ResponseBean findAll(){
       List<SupplierVO> supplierVOList =  supplierService.findAll();
        return ResponseBean.success(supplierVOList);
    }
}
